package com.it.order.api;

import com.it.order.entity.Order;
import com.it.order.service.OrderService;
import com.it.order.vo.OrderVO;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * 订单服务的实现
 */
@DubboService(version = "${order.service.version}")
public class ApiOrderImpl implements  OrderApi  {
    @Autowired
    private OrderService orderService;
    public void addOrder(OrderVO orderVO) {
        Order order = new Order();
        BeanUtils.copyProperties(orderVO,order);
        orderService.insert(order);
    }

    public void delOrder(long orderId) {
        orderService.deleteById(orderId);
    }

    public void updateOrderStatusById(OrderVO orderVO) {
        Order order = new Order();
        BeanUtils.copyProperties(orderVO,order);
        orderService.updateById(order);
    }

    @Transactional
    public OrderVO queryOrderByOrderId(long orderId) {
       Order order =  orderService.selectById(orderId);
        OrderVO orderVO = new OrderVO();
        BeanUtils.copyProperties(order,orderVO);
        return orderVO;
    }
}
